/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package epaper;

import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;

/**
 *
 * @author Puneet
 */
public class TOI extends CommonClient implements Callable {

   private static Map<Integer, String> cs = new HashMap<Integer, String>();

    
    public TOI(int city, String fileName, Date date) {

        super(null, city, fileName, date);
        pagecount = 50;
        populateCSMap();
        WorkProgress.getInstance().setIncrAmount(900/pagecount);
        buf = new byte[pagecount][];
    }
    

    void populateCSMap() {
        cs.put(Cities.getInstance().AHMEDABAD, "TOIA");
        cs.put(Cities.getInstance().BANGALORE, "TOIBG");
        cs.put(Cities.getInstance().CHENNAI, "TOICH");
        cs.put(Cities.getInstance().DELHI, "CAP");
        cs.put(Cities.getInstance().HYDERABAD, "TOIH");
        cs.put(Cities.getInstance().JAIPUR, "TOIJ");
        cs.put(Cities.getInstance().KOLKATA, "TOIKM");
        cs.put(Cities.getInstance().LUCKNOW, "TOIL");
        cs.put(Cities.getInstance().MUMBAI, "TOIM");
        cs.put(Cities.getInstance().PUNE, "TOIPU");
    }

    public void buildURL(String lang, int city, Date date) {
        Format format = new SimpleDateFormat("yyyy/MM/dd");
        String dateStr = format.format(date);
        String pageStr = new SimpleDateFormat("yyyy_M_d").format(date);
        urlStr = new StringBuilder("http://epaper.timesofindia.com/Repository/");
        mergePaper = new StringBuilder(basefile + "Times_Of_India");
        if (Cities.isValidCity(city)) {
            urlStr.append(cs.get(city)).append("/").append(dateStr).append("/").append(cs.get(city)).append("_").append(pageStr).append("_");
            mergePaper.append("_").append(Cities.getInstance().getCity(city)).append(pageStr).append(".pdf");
        } else {
            System.out.println("INVALID CITY");
            System.exit(0);
        }
    }

    public String buildPageUrl(int pagenumber){
        System.out.println("Print: "+urlStr);
        return urlStr.toString() + (pagenumber) + ".pdf";
    }
}
